﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Code4Public.Settings;

namespace Code4Public.ThemeDesigners
{
    [DefaultEvent("BodyThemeChanged")]
    public partial class ThemeBodyDesigner : UserControl
    {
        public ThemeBodyDesigner()
        {
            InitializeComponent();
        }

        private bool eventSuspended = false;

        public void SuspendEventRaising()
        {
            eventSuspended = true;
            this.bodyBorderDesigner.SuspendEventRaising();
            this.bodyFontDesigner.SuspendEventRaising();
        }

        public void ResumeEventRaising()
        {
            eventSuspended = false;
            this.bodyFontDesigner.ResumeEventRaising();
            this.bodyBorderDesigner.ResumeEventRaising();
        }

        public event EventHandler BodyThemeChanged;

        private void bodyBorderDesigner_BorderPropertiesChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && BodyThemeChanged != null)
                BodyThemeChanged(this, new EventArgs());
        }

        private void numericUpDownBodyFontSize_ValueChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && BodyThemeChanged != null)
                BodyThemeChanged(this, new EventArgs());
        }

        private void bodyFontDesigner_FontPropertiesChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && BodyThemeChanged != null)
                BodyThemeChanged(this, new EventArgs());
        }

        private void colorPickerCodeBackColor_ColorChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && BodyThemeChanged != null)
                BodyThemeChanged(this, new EventArgs());
        }

        public BorderInfo MainContentBorder
        {
            get
            {
                return new BorderInfo()
                {
                    Bottom = this.bodyBorderDesigner.BorderBottom,
                    Left = this.bodyBorderDesigner.BorderLeft,
                    Right = this.bodyBorderDesigner.BorderRight,
                    Top = this.bodyBorderDesigner.BorderTop,
                    Color = this.bodyBorderDesigner.BorderColor
                };
            }

            set
            {
                this.bodyBorderDesigner.BorderBottom = value.Bottom;
                this.bodyBorderDesigner.BorderLeft = value.Left;
                this.bodyBorderDesigner.BorderRight = value.Right;
                this.bodyBorderDesigner.BorderTop = value.Top;
                this.bodyBorderDesigner.BorderColor = value.Color;
            }
        }

        public int MainContentFontSize
        {
            get
            {
                return (int)this.numericUpDownBodyFontSize.Value;
            }

            set
            {
                this.numericUpDownBodyFontSize.Value = value;
            }
        }

        public Color CodeContentBackColor
        {
            get
            {
                return this.colorPickerCodeBackColor.Color;
            }

            set
            {
                this.colorPickerCodeBackColor.Color = value;
            }
        }

        public FontInfo CodeContentFont
        {
            get
            {
                return new FontInfo(this.bodyFontDesigner.FontColor,
                    this.bodyFontDesigner.FontBold, this.bodyFontDesigner.FontItalic);
            }

            set
            {
                this.bodyFontDesigner.FontBold = value.Bold;
                this.bodyFontDesigner.FontItalic = value.Italic;
                this.bodyFontDesigner.FontColor = value.Color;
            }
        }

    }
}
